package org.halk.controller;

import org.apache.ibatis.annotations.Param;
import org.halk.entity.User;
import org.halk.mapper.TestMapper;
import org.halk.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @Resource
    private TestMapper testMapper;

    @GetMapping("/insert")
    public String insertTest() {
        testService.insertList();
        return "insert";
    }

    @GetMapping("/get")
    public List<User> get() {
        List<User> userList = testService.getAll();
        return userList;
    }


    @GetMapping("/get/2")
    public List<User> get2() {
        List<User> userList = testService.findUser();
        return userList;
    }

    @PostMapping("/login")
    public boolean login(@Param("name") String name, @Param("passwd") String passwd) {
        System.out.println("11111");
        if (Objects.equals(name, "halk") && Objects.equals(passwd, "123")) {
            return true;
        }
        return false;
    }


    @GetMapping("/test")
    @Transactional
    public String test01() {
        testService.test01();
//        testService.test03();
//        testService.test04();
//
//        User user = new User()
//                .setAge(88774)
//                .setCreateTime(new Date())
//                .setName("第" + 123 + "个");
//        System.out.println(user);
//        System.out.println("===============");
//        this.testMapper.insert(user);
////
//        int i = 1/0;
//        System.out.println(1111);
        return "ok";
    }
}
